<html>
<head><meta charset="utf-8"><title>GlobalAlloc memory alignment · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/GlobalAlloc.20memory.20alignment.html">GlobalAlloc memory alignment</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="227970928"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/GlobalAlloc%20memory%20alignment/near/227970928" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Anatol Ulrich <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/GlobalAlloc.20memory.20alignment.html#227970928">(Feb 26 2021 at 18:31)</a>:</h4>
<p>when implementing <code>GlobalAlloc::alloc</code> by forwarding it to a system <code>malloc</code> (in my case, FreeBSD kernel malloc), is passing <code>layout.size()</code> enough or do I have to ensure <code>layout.align()</code> in some way also? (if so, how?)</p>



<a name="227971513"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/GlobalAlloc%20memory%20alignment/near/227971513" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/GlobalAlloc.20memory.20alignment.html#227971513">(Feb 26 2021 at 18:35)</a>:</h4>
<p>You must ensure alignment requirements are matched. If the kernel API doesn't offer a malloc variant that takes in an alignment (like posix_memalign), you can either reject allocation requests with alignments higher than the allocator's minimum alignment, or overallocate and adjust the pointer to an aligned point of the allocation</p>



<a name="227971543"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/GlobalAlloc%20memory%20alignment/near/227971543" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Anatol Ulrich <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/GlobalAlloc.20memory.20alignment.html#227971543">(Feb 26 2021 at 18:35)</a>:</h4>
<p>that makes sense. Thanks!</p>



<a name="227971546"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/GlobalAlloc%20memory%20alignment/near/227971546" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/GlobalAlloc.20memory.20alignment.html#227971546">(Feb 26 2021 at 18:35)</a>:</h4>
<p>the windows implementation of the System allocator does the second if you want something to reference</p>



<a name="227971606"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/GlobalAlloc%20memory%20alignment/near/227971606" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Anatol Ulrich <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/GlobalAlloc.20memory.20alignment.html#227971606">(Feb 26 2021 at 18:36)</a>:</h4>
<p>even better :)</p>



<a name="227979110"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/GlobalAlloc%20memory%20alignment/near/227979110" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/GlobalAlloc.20memory.20alignment.html#227979110">(Feb 26 2021 at 19:28)</a>:</h4>
<p>I'm surprised that Windows doesn't have an allocator with N^2 config knobs and sliders.</p>



<a name="227985613"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/GlobalAlloc%20memory%20alignment/near/227985613" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/GlobalAlloc.20memory.20alignment.html#227985613">(Feb 26 2021 at 20:11)</a>:</h4>
<p>well it's got three ways to access "basically all the same" allocator.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>